macro(build_target MODULE PROTO_DIR DEPS)
	CollectSourceFiles(${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES)
	GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
	list(APPEND PRIVATE_SOURCES config.json)
    if (NOT "${PROTO_DIR}"  STREQUAL "")
        set(PROTOBUF_IMPORT_DIRS ${Protobuf_INCLUDE_DIRS})
        file(GLOB_RECURSE PROTO_LIST ${PROTO_DIR}/*.proto)
        protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
        list(APPEND PRIVATE_SOURCES ${PROTO_SRCS} ${PROTO_HDRS})
    endif()
    
	add_executable(${MODULE} ${PRIVATE_SOURCES})
	target_link_libraries(${MODULE} PRIVATE emoney-core-interface server proto)
	if(NOT "${DEPS}"  STREQUAL "")
        string(REPLACE " " ";" DEP_LIST ${DEPS})
        message("deps=" ${DEPS})
        target_link_libraries(${MODULE} PRIVATE ${DEP_LIST})
    endif()

	target_include_directories(${MODULE}   
      PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR})
	 
    if (WIN32)
        add_custom_command(TARGET ${MODULE} 
            POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/conf/${MODULE}/)
        add_custom_command(TARGET ${MODULE}
            POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/config.json ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/conf/${MODULE}/)     
    endif()

    if (UNIX)
      install(TARGETS ${MODULE} DESTINATION ${CMAKE_BINARY_DIR}/bin)
      install(FILES config.json DESTINATION ${CMAKE_BINARY_DIR}/bin/conf/${MODULE})
    elseif (WIN32)
      install(FILES config.json DESTINATION "${CMAKE_INSTALL_PREFIX}")
    endif()

	set_target_properties(${MODULE} PROPERTIES FOLDER "module")   
endmacro()

#-----------------------------------------------------------------------
